package com.app.qtjk.lsh.ctrl;
import java.util.ArrayList;
import java.util.HashMap;

import com.app.common.utils.FilterUtil;
import com.app.common.utils.StringUtil;
import com.css.sword.kernel.utils.SwordLogUtils;
import com.css.sword.kernel.utils.SwordServiceUtils;
import com.css.sword.platform.web.controller.BaseDomainCtrl;
import com.css.sword.platform.web.controller.annotations.CTRL;
import com.css.sword.platform.web.event.IReqData;
import com.css.sword.platform.web.event.IResData;
import com.css.sword.platform.web.event.SwordRes;


@CTRL("QrcodeCtrl")
public class QrcodeCtrl extends BaseDomainCtrl {

	private static SwordLogUtils log = SwordLogUtils.getLogger(QrcodeCtrl.class);

	/**
	 * 用户扫描二维码
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public IResData userScanQrcode(IReqData req) throws Exception{

		log.debug("开始进入 QrcodeCtrl_userScanQrcode 方法。");

		IResData res = new SwordRes();
		HashMap commonMap = new HashMap();
		ArrayList commonList = new ArrayList();		
		HashMap hashMap = new HashMap();
		try {
			if (FilterUtil.checkToken(req) == false) {
				hashMap.put("returnStatus", "false");
				hashMap.put("msg", "请求口令错误！");
			}else {
				hashMap.put("returnStatus", "true");
				//调用检查是否有密码接口
				res = (IResData) SwordServiceUtils.callService("QRcodeService_sfHavePassword", req);
				hashMap.put("qrcodeExist", StringUtil.parse2String(res.get("qrcodeExist")));
				//二维码存在时
				if ("true".equals(res.get("qrcodeExist"))) {
					hashMap.put("sfHavePassword", StringUtil.parse2String(res.get("sfHavePassword")));
					//二维码密码不存在时
					if ("false".equals(res.get("sfHavePassword"))) {
						//调用增加财富值接口
						res = (IResData) SwordServiceUtils.callService("QRcodeService_addWealth", req);
						hashMap.put("sfScan", StringUtil.parse2String(res.get("sfScan")));
						//用户未扫描过时
						if ("false".equals(res.get("sfScan"))) {
							hashMap.put("sfEnough", StringUtil.parse2String(res.get("sfEnough")));
							//商户财富值充足时
							if ("true".equals(res.get("sfEnough"))) {
								hashMap.put("addSuccess", StringUtil.parse2String(res.get("addSuccess")));
								hashMap.put("addWealth", StringUtil.parse2String(res.get("addWealth")));
							}
						}
					}
				}
			}
		} catch (Exception e) {
			log.debug("---------------系统发生异常！---------------");
			e.printStackTrace();
			hashMap.put("returnStatus", "false");
			hashMap.put("msg", "出现异常！");
		} finally {
			commonMap.put("commonData", hashMap);
			commonList.add(commonMap);
			res.addListWithDataName("returnData", commonList);
		}
		
		return res;
	}

	 		
	/**
	 * 验证密码后加财富值
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public IResData verifyPassword(IReqData req) throws Exception{

		log.debug("开始进入 QrcodeCtrl_verifyPassword 方法。");

		IResData res = new SwordRes();
		HashMap commonMap = new HashMap();
		ArrayList commonList = new ArrayList();		
		HashMap hashMap = new HashMap();
		try {
			if (FilterUtil.checkToken(req) == false) {
				hashMap.put("returnStatus", "false");
				hashMap.put("msg", "请求口令错误！");
			}else {
				hashMap.put("returnStatus", "true");
				//调用检查是否有密码接口
				res = (IResData) SwordServiceUtils.callService("QRcodeService_sfHavePassword", req);
				hashMap.put("qrcodeExist", StringUtil.parse2String(res.get("qrcodeExist")));
				//二维码存在时
				if ("true".equals(res.get("qrcodeExist"))) {
					//调用检查二维码密码是否正确接口
					res = (IResData) SwordServiceUtils.callService("QRcodeService_checkPassword", req);
					hashMap.put("passwordSfRight", StringUtil.parse2String(res.get("passwordSfRight")));
					if ("true".equals(res.get("passwordSfRight"))) {
						//调用增加财富值接口
						res = (IResData) SwordServiceUtils.callService("QRcodeService_addWealth", req);
						hashMap.put("sfScan", StringUtil.parse2String(res.get("sfScan")));
						//用户未扫描过时
						if ("false".equals(res.get("sfScan"))) {
							hashMap.put("sfEnough", StringUtil.parse2String(res.get("sfEnough")));
							//商户财富值充足时
							if ("true".equals(res.get("sfEnough"))) {
								hashMap.put("addSuccess", StringUtil.parse2String(res.get("addSuccess")));
								hashMap.put("addWealth", StringUtil.parse2String(res.get("addWealth")));
							}
						}
					}
				}	
			}		
		} catch (Exception e) {
			log.debug("---------------系统发生异常！---------------");
			e.printStackTrace();
			hashMap.put("returnStatus", "false");
			hashMap.put("msg", "出现异常！");
		} finally {
			commonMap.put("commonData", hashMap);
			commonList.add(commonMap);
			res.addListWithDataName("returnData", commonList);
		}			
					
		return res;

	}

	 		


}